﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using System.Web.Routing;

using Blog.TemplateViewEngine;

namespace Blog
{
    public class GlobalApplication : System.Web.HttpApplication
    {
        public static void RegisterRoutes()
        {
            RouteTable.Routes.MapRoute("post", "blog/post/{url}", new { controller = "Blog", action = "ViewPost" }, new { url ="^([a-zA-Z0-9+-]*([a-zA-Z0-9+-_]+\\.)*[a-zA-Z0-9+-_]+)$" });
            RouteTable.Routes.MapRoute("archive", "blog/archives/{year}/{month}/{page}", new { controller = "Blog", action = "Archive", year = (int?)null, month = (int?)null, page = (int)1 }, new { year = "(19|20)\\d\\d", month = "(0?[1-9]|1[012])", page = "[1-9]+[0-9]*" });
            //RouteTable.Routes.MapRoute("archive-year", "blog/archives/{year}", new { controller = "Blog", action = "Archive_Year", year = (int?)null, month = (int?)null }, new { year = "(19|20)\\d\\d" });
            //RouteTable.Routes.MapRoute("archive", "blog/archives/", new { controller = "Blog", action = "Archive", year = (int?)null, month = (int?)null });
            RouteTable.Routes.MapRoute("tag", "blog/tags/{tag}/{page}", new { controller = "Blog", action = "Tag", page = (int)1 }, new { tag = "^([a-zA-Z0-9+-]*([a-zA-Z0-9+-_]+\\.)*[a-zA-Z0-9+-_]+)$", page = "[1-9]+[0-9]*" });
            RouteTable.Routes.MapRoute("home", "blog/{page}", new { controller = "Blog", action = "Index", page = (int)1 }, new { page = "[1-9]+[0-9]*" });

            //routes.MapRoute("", "{controller}.mvc/{action}/{id}", new { controller = "Blog", action = "Index", id = "" }, new { controller = "Blog" });

            //routes.MapRoute("default", "Default.aspx", new { controller = "Blog", action = "Index" });
        }

        protected void Application_Start(object sender, EventArgs e)
        {
            RegisterRoutes();

            // Register the ViewEngine
            ControllerBuilder.Current.SetControllerFactory(new TemplateControllerFactory());
        }
    }
}